import 'package:aichat_flutter_wallet/module_common/widgets/image/public_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class DAppHistoryList extends StatelessWidget {
  final String name;
  final String description;
  final String image;
  final void Function() onClick;
  final void Function() onDelete;

  DAppHistoryList({
    required this.name,
    this.description = '',
    this.image = '',
    void Function()? onClick,
    void Function()? onDelete,
  })  : onClick = onClick ?? (() {}),
        onDelete = onDelete ?? (() {});

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return InkWell(
      onTap: () {
        onClick();
      },
      child: Container(
        height: 70.w,
        width: double.infinity,
        padding: EdgeInsets.only(left: 20.w, right: 20.w, top: 12.w, bottom: 12.w),
        child: Row(
          children: [
            ClipRRect(
              borderRadius: BorderRadius.circular(50.w),
              child: PublicImage(image: image, width: 46.w, height: 46.w),
            ),
            SizedBox(
              width: 10.w,
            ),
            Expanded(
                flex: 1,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      name.isEmpty ? "----" : name,
                      overflow: TextOverflow.ellipsis,
                      maxLines: 1,
                      style: TextStyle(
                          fontSize: 14.sp,
                          height: 20.w / 14.w,
                          fontWeight: FontWeight.w500,
                          color: Color.fromRGBO(51, 51, 51, 1)),
                    ),
                    if (description.length > 0 && name.length > 0)
                      SizedBox(
                        height: 3.w,
                      ),
                    if (description.length > 0)
                      Text(
                        description,
                        overflow: TextOverflow.ellipsis,
                        maxLines: 1,
                        style: TextStyle(
                            fontSize: 12.sp,
                            height: 17.w / 12.w,
                            fontWeight: FontWeight.w400,
                            color: Color.fromRGBO(190, 189, 202, 1)),
                      ),
                  ],
                )),
            GestureDetector(
                onTap: () {
                  onDelete();
                },
                behavior: HitTestBehavior.translucent,
                child: Container(
                  padding: EdgeInsets.only(left: 10.w),
                  child: Image.asset(
                    'assets/images/dapp/history_close.png',
                    width: 16.w,
                    height: 16.w,
                  ),
                )),
          ],
        ),
      ),
    );
  }
}
